﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data ;
using System.Data .SqlClient ;
using dhDataAcess.dataAcess .sysDataSetTableAdapters ;
using dhDataAcess.Model ;

namespace dhDataAcess.sysDAL
{
  public class itemListDAL
    {
        string tableName = "itemList";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public itemListDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction;
            conn=_conn;
        }
      
        /// <summary>
        /// 插入一行模块表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>

        public int itemListInsert(itemListModel deptRow)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string insertStr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();
           // string insertStr = "insert into itemList (mark,updateUser,updateDate,createUser,createDate,itemDataType,itemDispNo,itemWidth,itemDispIndex,itemDispJ,itemDispE,itemDispC,itemName,temNum,moduleNum) values(@mark,@updateUser,@updateDate,@createUser,@createDate,@itemDataType,@itemDispNo,@itemWidth,@itemDispIndex,@itemDispJ,@itemDispE,@itemDispC,@itemName,@temNum,@moduleNum)";
            
            SqlParameter[] para = {
                                  new SqlParameter ("@mark",deptRow .mark ),
                                  new SqlParameter ("@updateUser",deptRow .updateUser ),
                                  new SqlParameter ("@updateDate",deptRow .updateDate),
                                  new SqlParameter ("@createUser",deptRow .createUser),
                                  new SqlParameter ("@createDate",deptRow .createDate),
                                  new SqlParameter ("@itemDataType",deptRow .itemDataType ),
                                  new SqlParameter ("@itemDispNo",deptRow .itemDispNo),
                                  new SqlParameter ("@itemWidth",deptRow .itemWidth),
                                  new SqlParameter ("@itemDispIndex",deptRow .itemDispIndex),
                                  new SqlParameter ("@itemDispJ",deptRow .itemDispJ),
                                  new SqlParameter ("@itemDispE",deptRow .itemDispE),
                                  new SqlParameter ("@itemDispC",deptRow .itemDispC),
                                  new SqlParameter ("@itemName",deptRow .itemName),
                                  new SqlParameter ("@itemNum",deptRow .itemNum),
                                  new SqlParameter ("@moduleNum",deptRow .moduleNum )
                                 
                                   };

            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }

        /// <summary>
        /// 更新一行模块表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
 
        public int itemListUpdate(itemListModel deptRow)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updateStr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
           // string updateStr = "update itemList set mark=@mark,updateUser=@updateUser,updateDate=@updateDate,createUser=@createUser,createDate=@createDate,itemDataType=@itemDataType,itemDispNo=@itemDispNo,itemWidth=@itemWidth,itemDispIndex=@itemDispIndex,itemDispJ=@itemDispJ,itemDispE=@itemDispE,itemDispC=@itemDispC,itemName=@itemName,temNum=@temNum where moduleNum=@moduleNum";
            SqlParameter[] para = {
                                   new SqlParameter ("@mark",deptRow .mark ),
                                  new SqlParameter ("@updateUser",deptRow .updateUser ),
                                  new SqlParameter ("@updateDate",deptRow .updateDate),
                                  new SqlParameter ("@createUser",deptRow .createUser),
                                  new SqlParameter ("@createDate",deptRow .createDate),
                                  new SqlParameter ("@itemDataType",deptRow .itemDataType ),
                                  new SqlParameter ("@itemDispNo",deptRow .itemDispNo),
                                  new SqlParameter ("@itemWidth",deptRow .itemWidth),
                                  new SqlParameter ("@itemDispIndex",deptRow .itemDispIndex),
                                  new SqlParameter ("@itemDispJ",deptRow .itemDispJ),
                                  new SqlParameter ("@itemDispE",deptRow .itemDispE),
                                  new SqlParameter ("@itemDispC",deptRow .itemDispC),
                                  new SqlParameter ("@itemName",deptRow .itemName),
                                  new SqlParameter ("@itemNum",deptRow .itemNum),
                                  new SqlParameter ("@moduleNum",deptRow .moduleNum )
                                  };
           
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updateStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }


        /// <summary>
        /// 删除一行模块表数据 
        /// </summary>
        /// <param name="itemNum"></param>
        /// <returns></returns>

        public int itemListDel(string itemNum)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deleteStr = baseBLL.dTableColumnRead.delSqlStr(tableName).ToString();
           // string deleteStr = "delete itemList where temNum=@temNum";
            SqlParameter[] para = {
                                new SqlParameter ("@itemNum",itemNum)
                              };

            cmd.Parameters.AddRange(para);
            cmd.CommandText = deleteStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
      
        /// <summary>
        /// 根据列编号返回列名称
        /// </summary>
        /// <param name="itemNum"></param>
        /// <returns></returns>

        public string itemListretName(string itemNum)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string selectStr = "selete itemName from itemList where temNum=@temNum";
            SqlParameter[] para = {
                                new SqlParameter ("@temNum",itemNum),
                              };

            cmd.Parameters.AddRange(para);
            cmd.CommandText = selectStr;
            cmd.Transaction = tran;
            SqlDataReader rdr = cmd.ExecuteReader();
            string itemName = null;
            while (rdr.Read())
            {
                itemName = rdr[0].ToString();
            }

            return itemName;
        }
    }
}
